package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysOwner;
import com.ruoyi.system.service.ISysOwnerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 卖家Controller
 *
 * @author silencezheng
 * @date 2022-11-16
 */
@RestController
@RequestMapping("/system/owner")
public class SysOwnerController extends BaseController
{
    @Autowired
    private ISysOwnerService sysOwnerService;

    /**
     * 查询卖家列表
     */
    @PreAuthorize("@ss.hasPermi('system:owner:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOwner sysOwner)
    {
        startPage();
        List<SysOwner> list = sysOwnerService.selectSysOwnerList(sysOwner);
        return getDataTable(list);
    }

    /**
     * 导出卖家列表
     */
    @PreAuthorize("@ss.hasPermi('system:owner:export')")
    @Log(title = "卖家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOwner sysOwner)
    {
        List<SysOwner> list = sysOwnerService.selectSysOwnerList(sysOwner);
        ExcelUtil<SysOwner> util = new ExcelUtil<SysOwner>(SysOwner.class);
        util.exportExcel(response, list, "卖家数据");
    }

    /**
     * 获取卖家详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:owner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysOwnerService.selectSysOwnerById(id));
    }

    /**
     * 新增卖家
     */
    @PreAuthorize("@ss.hasPermi('system:owner:add')")
    @Log(title = "卖家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOwner sysOwner)
    {
        sysOwner.setCreateBy(getUsername());
        return toAjax(sysOwnerService.insertSysOwner(sysOwner));
    }

    /**
     * 修改卖家
     */
    @PreAuthorize("@ss.hasPermi('system:owner:edit')")
    @Log(title = "卖家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOwner sysOwner)
    {
        return toAjax(sysOwnerService.updateSysOwner(sysOwner));
    }

    /**
     * 删除卖家
     */
    @PreAuthorize("@ss.hasPermi('system:owner:remove')")
    @Log(title = "卖家", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysOwnerService.deleteSysOwnerByIds(ids));
    }
}
